package ThreadDemo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2025-03-20
 * Time: 20:03
 */
public class ThreadDemo13 {
    private static long result = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(
                ()->{
                    long tmp = 0;
                    for (long i = 0; i <= 50_0000_0000L; i++) {
                        tmp += i;
                    }
                    result += tmp;
                }
        );
        Thread t1 = new Thread(
                ()->{
                    long tmp = 0;
                    for (long i = 50_0000_0001L; i <= 100_0000_0000L; i++) {
                        tmp += i;
                    }
                    result += tmp;
                }
        );
        t.start();
        t1.start();
        //记录开始时间
        long start = System.currentTimeMillis();

        t.join();//main主线程最后执行，在t线程结束之后再执行main线程
        t1.join();//在t1线程执行结束后在执行main线程

        //记录结束时间
        long end = System.currentTimeMillis();

        System.out.println("rusult = "+result);
        System.out.println("time = "+(end-start)+"毫秒");
    }
}
